package servlet;

import Util.Account;
import Util.MysqlOperation;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
@WebServlet("/ManageServlet")
public class ManageServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setCharacterEncoding("UTF-8");
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        HttpSession session=request.getSession(true);
        String pwd,aim;
        Account acc;
        acc = (Account) session.getAttribute("Account") ;
        pwd = request.getParameter("password");
        if (pwd != null && !pwd.equals("")) acc.setPassword(pwd);
        MysqlOperation.updateAccount(acc);
        response.sendRedirect("./index.jsp");
    }
}
